﻿using System;
using ch06.binary.interpreter;

namespace ch06.binary
{
    internal struct MemArg
    {
        internal uint Align;
        internal uint Offset;

        public override string ToString()
        {
            return '{' + $"{Align} {Offset}" + '}';
        }
    }

    internal struct BlockArgs
    {
        internal BlockType BT;
        internal Instruction[] Instrs;

        public override string ToString()
        {
            return "{" + BT + "[" + string.Join(" ", Instrs) + "]}";
        }
    }

    internal delegate void InstrFn(ref Vm vm, object args);

    public struct Instruction
    {
        internal byte Opcode;
        internal object Args;

        internal string GetOpname()
        {
            return OpNames.GetOpNameArr()[Opcode];
        }

        public override string ToString()
        {
            return OpNames.GetOpNameArr()[Opcode];
        }
    }

    // block & loop
    public struct IfArgs
    {
        internal BlockType BT;
        internal Instruction[] Instrs1;
        internal Instruction[] Instrs2;

        public override string ToString()
        {
            return "{" + BT + "[" + string.Join(" ", Instrs1) + "] [" + string.Join(" ", Instrs2) + "]}";
        }
    }

    public struct BrTableArgs
    {
        internal uint[] Labels;
        internal uint Default;

        public override string ToString()
        {
            return "{[" + $"{string.Join(" ", Labels)}" + "] " + $"{Default}" + "}";
        }
    }
}